package com.pheruagor.handmanager {

    import com.pheruagor.handmanager.controller.CloseClubCreationPopUpCommand;
    import com.pheruagor.handmanager.controller.CloseMemberEditionPopUpCommand;
    import com.pheruagor.handmanager.controller.CloseStartingPopUpCommand;
    import com.pheruagor.handmanager.controller.OpenClubCreationPopUpCommand;
    import com.pheruagor.handmanager.controller.OpenClubViewerCommand;
    import com.pheruagor.handmanager.controller.OpenMemberEditionPopUpCommand;
    import com.pheruagor.handmanager.controller.OpenStartingPopUpCommand;
    import com.pheruagor.handmanager.controller.ShutdownCommand;
    import com.pheruagor.handmanager.controller.StartupCommand;

    import mx.core.WindowedApplication;

    import org.puremvc.as3.patterns.facade.*;

    /**
     * A concrete <code>Facade</code> for the <code>CodePeek</code> application.
     * <P>
     * The main job of the <code>ApplicationFacade</code> is to act as a single
     * place for mediators, proxies and commands to access and communicate
     * with each other without having to interact with the Model, View, and
     * Controller classes directly. All this capability it inherits from
     * the PureMVC Facade class.</P>
     *
     * <P>
     * This concrete Facade subclass is also a central place to define
     * notification constants which will be shared among commands, proxies and
     * mediators, as well as initializing the controller with Command to
     * Notification mappings.</P>
     * @author pheruagor
     */
    public class ApplicationFacade extends Facade {

        // Notification name constants
        public static const STARTUP:String = "startup";
        public static const SHUTDOWN:String = "shutdown";

        //-----------------------------------------------------
        // Initialization
        //-----------------------------------------------------
        /**
         * Singleton ApplicationFacade Factory Method
         */
        public static function getInstance():ApplicationFacade {
            if (instance == null) {
                instance = new ApplicationFacade();
            }

            return instance as ApplicationFacade;
        }

        /**
         * Register Commands with the Controller
         */
        override protected function initializeController():void {
            super.initializeController();

            registerCommand(STARTUP, StartupCommand);
            registerCommand(SHUTDOWN, ShutdownCommand);
            registerCommand(OpenStartingPopUpCommand.NAME, OpenStartingPopUpCommand);
            registerCommand(CloseStartingPopUpCommand.NAME, CloseStartingPopUpCommand);
            registerCommand(OpenClubCreationPopUpCommand.NAME, OpenClubCreationPopUpCommand);
            registerCommand(CloseClubCreationPopUpCommand.NAME, CloseClubCreationPopUpCommand);
            registerCommand(OpenClubViewerCommand.NAME, OpenClubViewerCommand);
            registerCommand(OpenMemberEditionPopUpCommand.NAME, OpenMemberEditionPopUpCommand);
            registerCommand(CloseMemberEditionPopUpCommand.NAME, CloseMemberEditionPopUpCommand);
        }

        /**
         * The view hierarchy has been built, so start the application.
         */
        public function startup(app:WindowedApplication):void {
            sendNotification(STARTUP, app);
        }

    }
}